<template>
  <view class="content">
    <view class="showModle">
      <view class="page_section_spacing">
        <view class="swiper_item">
          <image class="s_hide" src="../../static/img/hide.png" v-on:click="clickHide"></image>
          <view class="s_cant">
            <image class="s_code" :src="regUrl"></image>
            <view v-if="mType == 'reg'" class="s_titil">微信扫一扫注册</view>
            <view v-else class="s_titil">请扫码确认身份</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { GET_LOGIN_QRCODE, GET_LOGIN_STATUS, INTEGRAL_ORDER_ADD } from '@/api'
export default {
  props: {
    mType: {
      default: 'reg',
      type: String
    },
  },
  data() {
    return {
      tableId: this.$store.state.storeConf.table_id,
      deviceNum: this.$store.state.storeConf.device_num,
      storeId: this.$store.state.storeConf.store_id,
      userId: null,
      regUrl: 'https://wkbar.nbxinyitec.com/uploads/code/account-center.png',
      loginStatus: null
    };
  },
  mounted() {
    if (this.mType === 'integralPay') {
      this.getLoginQrcode()
      this.loginStatus = setInterval(this.getLoginStatus, 2000);
    }
  },
  methods: {
    getLoginQrcode() {
      let that = this
      that.$_get(GET_LOGIN_QRCODE, {store_id: that.tableId, table_id: that.storeId}).then(res => {
        if (res.code === 1) {
          that.regUrl = res.data
        }
      })
    },
    getLoginStatus() {
      let that = this
      that.$_get(GET_LOGIN_STATUS, {store_id: that.tableId, table_id: that.storeId}).then(res => {
        if (res.code === 1 && res.msg === '已登陆') {
          that.userId = res.data.user_id
          that.$storage.set('userId', that.userId)
          clearInterval(that.loginStatus)
          that.goPay()
        }
      })
    },
    goPay() {
      let that = this;
      that.$_post(INTEGRAL_ORDER_ADD, { table_id: that.tableId, device_num: that.deviceNum, store_id: that.storeId, user_id: that.userId }).then(res => {
        if (res.code === 1) {
          that.$storage.set('orderNo', res.data.order_no)
          that.$storage.set('orderPrice', res.data.price)
          this.$emit('menberShow', false);
          that.$emit('cartHide', {
            cart: false,
            pay: true,
            payType: 'integral'
          });
        } else {
          that.$common.msgToShow(res.msg);
        }
      });
    },
    clickHide() {
      //点击隐藏
      clearInterval(this.loginStatus)
      this.$emit('menberShow', false);
    }
  }
};
</script>

<style lang="scss" scoped>
.page_section {
  position: relative;
}
.swiper_item {
  position: relative;
  background: #ffffff;
  width: 100%;
  height: 100%;
  text-align: center;
  border-radius: 10px;
}
.s_cant {
  padding: 5vw 9vw 0;
}
.s_hide {
  position: absolute;
  width: 22px;
  height: 22px;
  top: 20px;
  right: 24px;
}
.s_titil {
  padding-top: 4vw;
  font-size: 2vw;
}
.s_code {
  margin-top: 8vw;
  width: 25vw;
  height: 25vw;
}
</style>
